package com.example.learning_store;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.view.View;

import androidx.annotation.Nullable;

public class MySQliteOpenHelper extends SQLiteOpenHelper {
    private static SQLiteOpenHelper mInstance;
    public static synchronized SQLiteOpenHelper getInstance(Context context){
        if(mInstance==null){
            mInstance=new MySQliteOpenHelper(context,"lxh1.db",null,1);
        }
        return mInstance;
    }

    //构造函数私有化

    private MySQliteOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }
    //初始化,数据初始化，数据库第一次创建时用。此函数只执行一次。
    //主键必须唯一primary key
    @Override
    public void onCreate(SQLiteDatabase db) {
        String aql="create table persons(_id integer primary key autoincrement,name text)";
        db.execSQL(aql);
    }
    //更新
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
